Skip to content

feat(sdk): route chat.agent transcript persistence through a TranscriptStorage seam - #4893

Open
ericallam wants to merge 1 commit into
feat/transcript-snapshot-v2-tri-13667from
feat/transcript-storage-seam-tri-13667
Open

feat(sdk): route chat.agent transcript persistence through a TranscriptStorage seam#4893
ericallam wants to merge 1 commit into
feat/transcript-snapshot-v2-tri-13667from
feat/transcript-storage-seam-tri-13667

Conversation

@ericallam

@ericallam ericallam commented Sep 5, 2026

Copy link
Copy Markdown
Member

Summary

Introduces the TranscriptStorage seam inside chat.agent and makes the built-in snapshot writer its default implementation. No public option yet; the default path behaves as before, apart from the blob now being written as version 2.

Design

A storage has load (called once when a run boots to continue a conversation) and save (called after every turn, failed turn and history-changing action). save receives a changeset of id-addressed operations: put (upsert by message id), remove, truncateAfter and state, plus the stream cursors the next boot resumes from.

The runtime keeps a shadow of the transcript it last handed to save (ids in order plus a fingerprint per message) and diffs the accumulator against it. A changed message in the common prefix is an in-place put; anything past the prefix is one truncateAfter on the last common id followed by puts in order. Applying the result reproduces the accumulator exactly for any edit, and the common cases come out as the natural operations: a turn is two puts, an undo is one truncateAfter, a regenerate is a truncateAfter and a put. The shadow only advances when save resolves, so a failed save is folded into the next changeset; every operation is idempotent, so a retried changeset converges.

Every changeset also carries the whole transcript as it stands after the changes (entries with a final flag, plus the runtime's state). A row-per-message store applies the changes; a store that keeps the conversation as one document writes the transcript as-is and needs no state of its own between saves. The default storage is the second kind: it serialises the transcript and rewrites the blob, so a turn still costs one PUT and no GET, and nothing is held in memory between saves. The snapshot read and write helpers move to their own module so the storage can import them without a cycle; the test seams keep their import path.

@changeset-bot

changeset-bot Bot commented Sep 5, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 5b764c7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The change adds transcript storage with reducers, shadow-based diffs, pagination, cursors, and version 2 snapshot persistence. It adds injectable and production snapshot I/O paths with failure handling. Chat agent persistence now uses transcript changesets for loading, completed turns, actions, and errors. Mocks and integration tests support version 1 compatibility and version 2 message envelopes.

Merge Risk: 🟡 Moderate · up to 5b764

Continuation and failed-upload paths can persist incomplete or stale transcript data, and a snapshot transport security concern remains unresolved. These issues should be addressed before merge.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the design and implementation in detail, but it omits the required issue reference, checklist, Testing section, Changelog section, and Screenshots section from the repository … Add the required template sections. Include a closing issue reference, completed checklist items, explicit testing steps and results, a short changelog entry, and screenshots or an explicit indication that screenshots are not applicable.
Docstring Coverage ⚠️ Warning Docstring coverage is 63.16% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 11 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: routing chat.agent transcript persistence through a TranscriptStorage seam.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the design and implementation in detail, but it omits the required issue reference, checklist, Testing section, Changelog section, and Screenshots section from the repository template.

Full details: Docstring Coverage

Explanation

Docstring coverage is 63.16% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 11 files. (1 skipped: 1 too large.)

✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/transcript-storage-seam-tri-13667

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ericallam
ericallam force-pushed the feat/transcript-storage-seam-tri-13667 branch from 4c91a95 to a7e6626 Compare September 5, 2026 20:29
@pkg-pr-new

pkg-pr-new Bot commented Sep 5, 2026

Copy link
Copy Markdown

Open in StackBlitz

@trigger.dev/build

npm i https://pkg.pr.new/@trigger.dev/build@5b764c7

trigger.dev

npm i https://pkg.pr.new/trigger.dev@5b764c7

@trigger.dev/core

npm i https://pkg.pr.new/@trigger.dev/core@5b764c7

@trigger.dev/python

npm i https://pkg.pr.new/@trigger.dev/python@5b764c7

@trigger.dev/react-hooks

npm i https://pkg.pr.new/@trigger.dev/react-hooks@5b764c7

@trigger.dev/redis-worker

npm i https://pkg.pr.new/@trigger.dev/redis-worker@5b764c7

@trigger.dev/rsc

npm i https://pkg.pr.new/@trigger.dev/rsc@5b764c7

@trigger.dev/schema-to-json

npm i https://pkg.pr.new/@trigger.dev/schema-to-json@5b764c7

@trigger.dev/sdk

npm i https://pkg.pr.new/@trigger.dev/sdk@5b764c7

commit: 5b764c7

@ericallam
ericallam marked this pull request as ready for review September 5, 2026 20:33
devin-ai-integration[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

@ericallam
ericallam force-pushed the feat/transcript-storage-seam-tri-13667 branch 2 times, most recently from 49acce9 to f5c6372 Compare September 6, 2026 05:42
devin-ai-integration[bot]

This comment was marked as resolved.

@ericallam
ericallam force-pushed the feat/transcript-storage-seam-tri-13667 branch from f5c6372 to 15f04f2 Compare September 6, 2026 05:54
devin-ai-integration[bot]

This comment was marked as resolved.

@ericallam
ericallam force-pushed the feat/transcript-storage-seam-tri-13667 branch from 15f04f2 to 8ead6fd Compare September 6, 2026 06:18
devin-ai-integration[bot]

This comment was marked as resolved.

@ericallam
ericallam force-pushed the feat/transcript-storage-seam-tri-13667 branch from 8ead6fd to 85f3ff1 Compare September 7, 2026 07:48

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 new potential issue.

Devin Review

Comment thread packages/trigger-sdk/src/v3/ai.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/trigger-sdk/src/v3/chatSnapshotIo.ts (1)

112-162: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Propagate snapshot write failures before advancing the shadow. When presigning or uploading fails, writeChatSnapshot logs and resolves. snapshotTranscriptStorage.save then resolves, so saveTranscript assigns transcriptShadow = shadow for data that was not persisted. Later changesets omit the failed diff, and no retry occurs if the run ends first. Reject the write so the shadow remains unchanged and the next save retries the full diff.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: c6686b9a-d738-4074-9091-864aedf8390d

📥 Commits

Reviewing files that changed from the base of the PR and between 4c91a95 and 85f3ff1.

📒 Files selected for processing (4)
  • packages/trigger-sdk/src/v3/ai.ts
  • packages/trigger-sdk/src/v3/test/mock-chat-agent.ts
  • packages/trigger-sdk/src/v3/transcriptStorage.ts
  • packages/trigger-sdk/test/transcript-storage.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.

📜 Review details
⏰ Context from checks skipped due to timeout. (34)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (19, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (6, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (23, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (18, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (24, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (7, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (13, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (2, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (21, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (20, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (15, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (17, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (9, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (14, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (10, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (12, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (5, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (16, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (8, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (11, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (3, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (1, 24)
  • GitHub Check: internal / 🧪 Unit Tests: Internal
  • GitHub Check: sdk-compat / Node.js 26.4 (warp-ubuntu-latest-x64-4x)
  • GitHub Check: packages / 🧪 Unit Tests: Packages (3, 3)
  • GitHub Check: e2e-webapp / 🧪 E2E Tests: Webapp (2, 2)
  • GitHub Check: sdk-compat / Node.js 24.18 (warp-ubuntu-latest-x64-4x)
  • GitHub Check: sdk-compat / Cloudflare Workers
  • GitHub Check: sdk-compat / Deno Runtime
  • GitHub Check: packages / 🧪 Unit Tests: Packages (1, 3)
  • GitHub Check: e2e-webapp / 🧪 E2E Tests: Webapp (1, 2)
  • GitHub Check: sdk-compat / Bun Runtime
  • GitHub Check: packages / 🧪 Unit Tests: Packages (2, 3)
  • GitHub Check: Analyze (javascript-typescript)
🧰 Additional context used
📓 Path-based instructions (9)
Always import from `@trigger.dev/sdk`.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • packages/trigger-sdk/test/transcript-storage.test.ts
  • packages/trigger-sdk/src/v3/transcriptStorage.ts
  • packages/trigger-sdk/src/v3/test/mock-chat-agent.ts
  • packages/trigger-sdk/src/v3/ai.ts
We use vitest exclusively.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • packages/trigger-sdk/test/transcript-storage.test.ts
**Prefer static imports over dynamic imports.**

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • packages/trigger-sdk/test/transcript-storage.test.ts
  • packages/trigger-sdk/src/v3/transcriptStorage.ts
  • packages/trigger-sdk/src/v3/test/mock-chat-agent.ts
  • packages/trigger-sdk/src/v3/ai.ts
Add crumbs as you write code — not just when debugging.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • packages/trigger-sdk/test/transcript-storage.test.ts
  • packages/trigger-sdk/src/v3/transcriptStorage.ts
  • packages/trigger-sdk/src/v3/test/mock-chat-agent.ts
  • packages/trigger-sdk/src/v3/ai.ts
In the Trigger.dev SDK (packages/trigger-sdk), prefer isomorphic code like fetch and ReadableStream instead of Node.js-specific code

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Files:

  • packages/trigger-sdk/test/transcript-storage.test.ts
  • packages/trigger-sdk/src/v3/transcriptStorage.ts
  • packages/trigger-sdk/src/v3/test/mock-chat-agent.ts
  • packages/trigger-sdk/src/v3/ai.ts
Use vitest for all tests in the Trigger.dev repository

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Files:

  • packages/trigger-sdk/test/transcript-storage.test.ts
Use function declarations instead of default exports

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Files:

  • packages/trigger-sdk/test/transcript-storage.test.ts
  • packages/trigger-sdk/src/v3/transcriptStorage.ts
  • packages/trigger-sdk/src/v3/test/mock-chat-agent.ts
  • packages/trigger-sdk/src/v3/ai.ts
Use types over interfaces for TypeScript Avoid using enums; prefer string unions or const objects instead

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Files:

  • packages/trigger-sdk/test/transcript-storage.test.ts
  • packages/trigger-sdk/src/v3/transcriptStorage.ts
  • packages/trigger-sdk/src/v3/test/mock-chat-agent.ts
  • packages/trigger-sdk/src/v3/ai.ts
When creating or editing OTEL metrics (counters, histograms, gauges), ensure metric attributes have low cardinality by using only enums, booleans, bounded error codes, or bounded shard IDs Do not use high-cardinality attributes in OTEL metr...

📄 CodeRabbit inference engine (.cursor/rules/otel-metrics.mdc)

Files:

  • packages/trigger-sdk/test/transcript-storage.test.ts
  • packages/trigger-sdk/src/v3/transcriptStorage.ts
  • packages/trigger-sdk/src/v3/test/mock-chat-agent.ts
  • packages/trigger-sdk/src/v3/ai.ts
🧠 Learnings (2)
📓 Common learnings
Learnt from: ericallam
Repo: triggerdotdev/trigger.dev PR: 4893
File: packages/trigger-sdk/test/transcript-storage.test.ts:190-197
Timestamp: 2026-09-06T05:39:13.239Z
Learning: In `triggerdotdev/trigger.dev`, `packages/trigger-sdk/test/transcript-storage.test.ts` uses the existing `__setReadChatSnapshotImplForTests` and `__setWriteChatSnapshotImplForTests` hooks to test pure transcript reducer, diff, and storage-adapter behavior. The real snapshot I/O transport is covered separately by MinIO-backed webapp tests. Do not require testcontainers for this unit-test file.
Learnt from: ericallam
Repo: triggerdotdev/trigger.dev

Timestamp: 2026-09-06T05:56:52.840Z
Learning: In `triggerdotdev/trigger.dev` `packages/trigger-sdk/src/v3/transcriptStorage.ts`, a transcript entry saved with `final: false` must remain non-final when its `UIMessage` content is unchanged in later `diffTranscript()` calls. `TranscriptShadow.nonFinal` preserves this status. When the message content changes, `diffTranscript()` emits a `put` with final status so `reduceTranscriptChanges()` stores the entry as final.
📚 Learning: 2026-08-16T18:36:58.179Z
Learnt from: ericallam
Repo: triggerdotdev/trigger.dev PR: 4537
File: packages/trigger-sdk/test/normalizeKeyString.test.ts:1-2
Timestamp: 2026-08-16T18:36:58.179Z
Learning: For related SDK `chat.agent` tests in the Trigger.dev repository—including chat channels, handover, snapshot, and transport-event coverage—keep new test files under `packages/trigger-sdk/test/` rather than colocating them with the `packages/trigger-sdk/src/v3/` source files.

Applied to files:

  • packages/trigger-sdk/test/transcript-storage.test.ts
🪛 ast-grep (0.45.2)
packages/trigger-sdk/src/v3/ai.ts

[warning] 7035-7042: Avoid logging sensitive data
Context: logger.warn(
"chat.agent: snapshot write outside a turn failed; the change may not survive a continuation",
{
error: error instanceof Error ? error.message : String(error),
sessionId: sessionIdForSnapshot,
reason,
}
)
Note: [CWE-532] Insertion of Sensitive Information into Log File.

(log-sensitive-data-typescript)


[warning] 7084-7087: Avoid logging sensitive data
Context: logger.warn("chat.agent: transcript load failed; continuing from the stream tail", {
error: error instanceof Error ? error.message : String(error),
sessionId: sessionIdForSnapshot,
})
Note: [CWE-532] Insertion of Sensitive Information into Log File.

(log-sensitive-data-typescript)

🔇 Additional comments (1)
packages/trigger-sdk/test/transcript-storage.test.ts (1)

44-339: LGTM!

Comment thread packages/trigger-sdk/src/v3/ai.ts
Comment thread packages/trigger-sdk/src/v3/transcriptStorage.ts
@ericallam
ericallam force-pushed the feat/transcript-storage-seam-tri-13667 branch from 85f3ff1 to 627899d Compare September 7, 2026 08:16
…ptStorage seam

Introduces the TranscriptStorage interface (load/save over id-addressed changes: put, remove, truncateAfter, state) and makes the built-in snapshot writer its default implementation. The runtime keeps a shadow of the transcript it last saved and hands the storage the diff after every turn, failed turn and history-changing action, together with the stream cursors the next boot resumes from. The default storage reduces each changeset onto an in-memory copy and rewrites the blob as version 2, so a turn still costs one PUT and no GET, and the boot read goes through load.

The snapshot read/write helpers move to their own module so the storage can import them without a cycle; the test seams keep their import path. The mock chat agent harness now reports version 2 snapshots and accepts either version as a seed.
@ericallam
ericallam force-pushed the feat/transcript-storage-seam-tri-13667 branch from 627899d to 5b764c7 Compare September 7, 2026 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants